xquery version "1.0" encoding "Cp1252";
(:: pragma bea:global-element-parameter parameter="$cli_get_info_res1" element="ns2:cli_get_info_res" location="../../../CL_ATG_ClienteConsultar_IMPL/Resource/wsdl/cli_get_info_response.xsd" ::)
(:: pragma bea:global-element-parameter parameter="$getClientInfoRes1" element="ns3:getClientInfoRes" location="../../../CL_TRXCLI_ClienteConsulta_IMPL/Resources-v3.0/Schemas/TransacClienteMsg.xsd" ::)
(:: pragma bea:global-element-parameter parameter="$regiones" element="CrossRefecrence" location="../xsd/RegionesCrossReference.xsd" ::)
(:: pragma bea:global-element-return element="ns1:ListOfSoAccountInterface" location="../../../CL_SIEBEL_ClienteCrear_IMPL/Resource/wsdl/SO_Siebel_Account.wsdl" ::)
 
declare namespace xf = "http://tempuri.org/CL_OSB_ClienteCrear_COMP/Resource/xq/Atg2Siebel/";
declare namespace ns0 = "http://datos.sodimac.cl/Siebel";
declare namespace ns1 = "http://www.siebel.com/xml/SO%20Account%20Interface%205";
declare namespace ns2 = "http://www.falabella.com/schemas/cli_get_info_res";
declare namespace ns3 = "http://msg.sodimac.cl/TransacClienteMsg";
declare namespace ns5 = "http://datos.sodimac.cl/TransacCliente";
declare namespace ns4 = "http://datos.sodimac.com/commons_v2.0";



declare function xf:Atg2Siebel(
	$cli_get_info_res1 as element(ns2:cli_get_info_res),
    $getClientInfoRes1 as element(ns3:getClientInfoRes),
    $regiones as element(CrossRefecrence))
    as element(ns1:ListOfSoAccountInterface) {
        <ns1:ListOfSoAccountInterface>
            {
                let $account := $cli_get_info_res1/ns2:response/ns2:account
                return
                    <ns1:Account>
                              
                        {
                            if ( fn:string-length($getClientInfoRes1/ns3:ListOfSoAccountInterfaceTopElmt/ns5:ListOfSoAccountInterface/ns5:Account[1]/ns5:AccountId )  > 0 ) then 
                            	  <ns1:AccountId>{data($getClientInfoRes1/ns3:ListOfSoAccountInterfaceTopElmt/ns5:ListOfSoAccountInterface/ns5:Account[1]/ns5:AccountId)}</ns1:AccountId>  
                            else 
                            	()
                        }                     

                        {
                            if ( fn:string-length($getClientInfoRes1/ns3:ListOfSoAccountInterfaceTopElmt/ns5:ListOfSoAccountInterface/ns5:Account[1]/ns5:AccountId )  > 0 ) then 
                            	  <ns1:AccountStatus>Activo</ns1:AccountStatus>
                            else 
                            	(<ns1:AccountStatus>Importado</ns1:AccountStatus>)
                        }                     
                                                                  
                        
                        <ns1:AccountTypeCode>{ data($account/ns0:AccountTypeCode) }</ns1:AccountTypeCode>
                        {
                            for $Alias in $account/ns0:Alias
                            return
                                <ns1:Alias>{ data($Alias) }</ns1:Alias>
                        }
                        <ns1:CurrencyCode>{ data($account/ns0:CurrencyCode) }</ns1:CurrencyCode>
                        {
                            for $SOCustomerSince in $account/ns0:SOCustomerSince
                            return
                                <ns1:SOCustomerSince>{ data($SOCustomerSince) }</ns1:SOCustomerSince>
                        }
                        {
                            for $DateFormed in $account/ns0:DateFormed
                            return
                                <ns1:DateFormed>{ data($DateFormed) }</ns1:DateFormed>
                        }
                        {
                            for $HomePage in $account/ns0:HomePage
                            return
                                <ns1:HomePage>{ data($HomePage) }</ns1:HomePage>
                        }
                        {
                            for $IntegrationId in $account/ns0:IntegrationId
                            return
                                <ns1:IntegrationId>{ data($IntegrationId) }</ns1:IntegrationId>
                        }
                        {
                            for $LanguageCode in $account/ns0:LanguageCode
                            return
                                <ns1:LanguageCode>{ data($LanguageCode) }</ns1:LanguageCode>
                        }
                        {
                            for $SOEstadoComercial in $account/ns0:SOEstadoComercial
                            return
                                <ns1:SOEstadoComercial>{ data($SOEstadoComercial) }</ns1:SOEstadoComercial>
                        }
                        <ns1:Location>{ data($account/ns0:Location) }</ns1:Location>
                        <ns1:LocationType>{ data($account/ns0:LocationType) }</ns1:LocationType>
                        {
                            for $MainFaxNumber in $account/ns0:MainFaxNumber
                            return
                                <ns1:MainFaxNumber>{ data($MainFaxNumber) }</ns1:MainFaxNumber>
                        }
                        {
                            for $MainPhoneNumber in $account/ns0:MainPhoneNumber
                            return
                                <ns1:MainPhoneNumber>{ data($MainPhoneNumber) }</ns1:MainPhoneNumber>
                        }
  {
                                if ( fn:string-length(data($getClientInfoRes1/ns3:ListOfSoAccountInterfaceTopElmt/ns5:ListOfSoAccountInterface/ns5:Account/ns5:AccountId) )  = 0 ) then 
                                	<ns1:Name>{ data($account/ns0:Name) }</ns1:Name>   
                                else ()
                                	                            
                                
                        	
   }         
                        
                        {
                            for $ParentAccountId in $account/ns0:ParentAccountId
                            return
                                <ns1:ParentAccountId>{ data($ParentAccountId) }</ns1:ParentAccountId>
                        }
                        {
                            for $ParentAccountIntegrationId in $account/ns0:ParentAccountIntegrationId
                            return
                                <ns1:ParentAccountIntegrationId>{ data($ParentAccountIntegrationId) }</ns1:ParentAccountIntegrationId>
                        }
                        {
                            for $ParentAccountLocation in $account/ns0:ParentAccountLocation
                            return
                                <ns1:ParentAccountLocation>{ data($ParentAccountLocation) }</ns1:ParentAccountLocation>
                        }
                        {
                            for $ParentAccountName in $account/ns0:ParentAccountName
                            return
                                <ns1:ParentAccountName>{ data($ParentAccountName) }</ns1:ParentAccountName>
                        }
                        {
                            for $PriceList in $account/ns0:PriceList
                            return
                                <ns1:PriceList>{ data($PriceList) }</ns1:PriceList>
                        }
                        
                        <ns1:PrimaryOrganization>Sodimac Chile</ns1:PrimaryOrganization>

                        {
                            for $RevenueGrowth in $account/ns0:RevenueGrowth
                            return
                                <ns1:RevenueGrowth>{ data($RevenueGrowth) }</ns1:RevenueGrowth>
                        }
                        {
                            for $SOCalidadDeDatos in $account/ns0:SOCalidadDeDatos
                            return
                                <ns1:SOCalidadDeDatos>{ data($SOCalidadDeDatos) }</ns1:SOCalidadDeDatos>
                        }
                        <ns1:SOSource>{ data($account/ns0:SOSource) }</ns1:SOSource>
                        <ns1:Type>{ data($account/ns0:Type) }</ns1:Type>
                        {
                            for $ListOfAccount_BusinessAddress in $account/ns0:ListOfAccount_BusinessAddress
                            return
                                <ns1:ListOfAccount_BusinessAddress>
                                    {
                                        for $BusinessAddress in $ListOfAccount_BusinessAddress/ns0:BusinessAddress
                                        return
                                            <ns1:BusinessAddress>
                                                {
                                                    for $AddressId in $BusinessAddress/ns0:AddressId
                                                    return
                                                        <ns1:AddressId>{ data($AddressId) }</ns1:AddressId>
                                                }
                                                {
                                                    for $AddressIntegrationId in $BusinessAddress/ns0:AddressIntegrationId
                                                    return
                                                        <ns1:AddressIntegrationId>{ data($AddressIntegrationId) }</ns1:AddressIntegrationId>
                                                }
                                                {
                                                    for $City in $BusinessAddress/ns0:City
                                                    return
                                                        <ns1:City>{ data($City) }</ns1:City>
                                                }
                                                <ns1:Country>{ data($BusinessAddress/ns0:Country) }</ns1:Country>
                                                {
                                                    
                                                    for $region in $regiones/registro
                                                    where 
                                                    $region/@valorATG = $BusinessAddress/ns0:SOState
                                                    return
                                                        <ns1:SOState>{ data($region/@valorSIEBEL) }</ns1:SOState>
                                                }
                                                {
                                                    for $PostalCode in $BusinessAddress/ns0:PostalCode
                                                    return
                                                        <ns1:PostalCode>{ data($PostalCode) }</ns1:PostalCode>
                                                }

                                                <ns1:Province>{ data($BusinessAddress/ns0:City) }</ns1:Province>
                                                <ns1:StreetAddress>{ data($BusinessAddress/ns0:StreetAddress) }</ns1:StreetAddress>
                                                <ns1:StreetAddress2/>

                                                {
                                                    for $AddressName in $BusinessAddress/ns0:AddressName
                                                    return
                                                        <ns1:AddressName>{ data($AddressName) }</ns1:AddressName>
                                                }
                                                {
                                                    for $County in $BusinessAddress/ns0:County
                                                    return
                                                        <ns1:County>{ data($County) }</ns1:County>
                                                }
                                                {
                                                    for $SOUsoFacturacion in $BusinessAddress/ns0:SOUsoFacturacion
                                                    return
                                                        <ns1:SOUsoFacturacion>{ data($SOUsoFacturacion) }</ns1:SOUsoFacturacion>
                                                }
                                                {
                                                    for $SOUsoDespacho in $BusinessAddress/ns0:SOUsoDespacho
                                                    return
                                                        <ns1:SOUsoDespacho>{ data($SOUsoDespacho) }</ns1:SOUsoDespacho>
                                                }
                                                {
                                                    for $SOUsoCorrespondencia in $BusinessAddress/ns0:SOUsoCorrespondencia
                                                    return
                                                        <ns1:SOUsoCorrespondencia>{ data($SOUsoCorrespondencia) }</ns1:SOUsoCorrespondencia>
                                                }
                                                {
                                                    for $SOUsoCobranza in $BusinessAddress/ns0:SOUsoCobranza
                                                    return
                                                        <ns1:SOUsoCobranza>{ data($SOUsoCobranza) }</ns1:SOUsoCobranza>
                                                }
                                                {
                                                    for $SOUsoDocumentosPorCobrar in $BusinessAddress/ns0:SOUsoDocumentosPorCobrar
                                                    return
                                                        <ns1:SOUsoDocumentosPorCobrar>{ data($SOUsoDocumentosPorCobrar) }</ns1:SOUsoDocumentosPorCobrar>
                                                }
                                                {
                                                    for $SOUsoLegal in $BusinessAddress/ns0:SOUsoLegal
                                                    return
                                                        <ns1:SOUsoLegal>{ data($SOUsoLegal) }</ns1:SOUsoLegal>
                                                }
                                                {
                                                    for $StartDate in $BusinessAddress/ns0:StartDate
                                                    return
                                                        <ns1:StartDate>{ data($StartDate) }</ns1:StartDate>
                                                }
                                                {
                                                    for $EndDate in $BusinessAddress/ns0:EndDate
                                                    return
                                                        <ns1:EndDate>{ data($EndDate) }</ns1:EndDate>
                                                }
                                                <ns1:SOFechModDireccion>{fn:substring(data($cli_get_info_res1/ns2:response/ns2:update_date),1,10)  }</ns1:SOFechModDireccion>                                                                                                    
                                                <ns1:SOSistemModDireccion>ATG</ns1:SOSistemModDireccion>
                                                
                                            </ns1:BusinessAddress>
                                    }
                                </ns1:ListOfAccount_BusinessAddress>
                        }
                       (: {
                           for $ListOfAccount_SalesRep in $account/ns0:ListOfAccount_SalesRep
                            return
                                <ns1:ListOfAccount_SalesRep>
                                    {
                                        for $RelatedSalesRep in $ListOfAccount_SalesRep/ns0:RelatedSalesRep
                                        return
                                            <ns1:RelatedSalesRep>
                                                {
                                                    for $IsPrimaryMVG in $RelatedSalesRep/@IsPrimaryMVG
                                                    return
                                                        <ns1:IsPrimaryMVG>{ data($IsPrimaryMVG) }</ns1:IsPrimaryMVG>
                                                }
                                                <ns1:Position>{ data($RelatedSalesRep/ns0:Position) }</ns1:Position>
                                                {
                                                    for $PositionId in $RelatedSalesRep/ns0:PositionId
                                                    return
                                                        <ns1:PositionId>{ data($PositionId) }</ns1:PositionId>
                                                }
                                                {
                                                    for $PositionIntegrationId in $RelatedSalesRep/ns0:PositionIntegrationId
                                                    return
                                                        <ns1:PositionIntegrationId>{ data($PositionIntegrationId) }</ns1:PositionIntegrationId>
                                                }
                                                <ns1:Division>{ data($RelatedSalesRep/ns0:Division) }</ns1:Division>
                                                {
                                                    for $CCResponsable in $RelatedSalesRep/ns0:CCResponsable
                                                    return
                                                        <ns1:CCResponsable/>
                                                }
                                            </ns1:RelatedSalesRep>
                                    }
                                </ns1:ListOfAccount_SalesRep>
                        }:)
                        {
                            for $ListOfContact in $account/ns0:ListOfContact
                            return
                                <ns1:ListOfContact>
                                    {
                                    	         
                                        for $RelatedContact in $ListOfContact/ns0:RelatedContact
                                        return
                                            <ns1:RelatedContact>
                                            	{
                                            	for $RelatedContact in  $getClientInfoRes1/ns3:ListOfSoAccountInterfaceTopElmt/ns5:ListOfSoAccountInterface/ns5:Account/ns5:ListOfContact/ns5:RelatedContact                                      
                                            		where $RelatedContact/ns5:PersonUId=$getClientInfoRes1/ns3:ListOfSoAccountInterfaceTopElmt/ns5:ListOfSoAccountInterface/ns5:Account/ns5:Location
                                            	return 
                                             		 <ns1:ContactId>{ data($RelatedContact/ns5:ContactId) }</ns1:ContactId>
                                            	}
                                            	
                                                {
                                                
                                                    for $AssistantPhone in $RelatedContact/ns0:AssistantPhone
                                                    return
                                                        <ns1:AssistantPhone>{ data($AssistantPhone) }</ns1:AssistantPhone>
                                                }
                                                {
                                                    for $SOFechaNacimiento in $RelatedContact/ns0:SOFechaNacimiento
                                                    return
                                                        <ns1:SOFechaNacimiento>{ data($SOFechaNacimiento) }</ns1:SOFechaNacimiento>
                                                }
                                                {
                                                    for $CellularPhone in $RelatedContact/ns0:CellularPhone
                                                    return
                                                        <ns1:CellularPhone>{ data($CellularPhone) }</ns1:CellularPhone>
                                                }
                                                {
                                                    for $Citizenship in $RelatedContact/ns0:Citizenship
                                                    return
                                                        <ns1:Citizenship>{ data($Citizenship) }</ns1:Citizenship>
                                                }
                                                {
                                                    for $ContactId in $RelatedContact/ns0:ContactId
                                                    return
                                                        <ns1:ContactId>{ data($ContactId) }</ns1:ContactId>
                                                }                                                
                                               (: {
                                                    for $EmailAddress in $RelatedContact/ns0:EmailAddress
                                                    return
                                                        <ns1:EmailAddress>{ data($EmailAddress) }</ns1:EmailAddress>
                                                }:)
                                                {
                                                    for $SOIndicadorEmpleado in $RelatedContact/ns0:SOIndicadorEmpleado
                                                    return
                                                        <ns1:SOIndicadorEmpleado>{ data($SOIndicadorEmpleado) }</ns1:SOIndicadorEmpleado>
                                                }
                                                  {
                                                if ( fn:string-length(for $RelatedContact in  $getClientInfoRes1/ns3:ListOfSoAccountInterfaceTopElmt/ns5:ListOfSoAccountInterface/ns5:Account/ns5:ListOfContact/ns5:RelatedContact                                      
                                            		where $RelatedContact/ns5:PersonUId=$getClientInfoRes1/ns3:ListOfSoAccountInterfaceTopElmt/ns5:ListOfSoAccountInterface/ns5:Account/ns5:Location
                                                	return 'aaaaaa')  > 0 ) then 
                                                	()
                                                	else 
                                                	<ns1:FirstName>{ data($RelatedContact/ns0:FirstName) }</ns1:FirstName>
                                                	
                                                }
                                                {
                                                
                                                    if ( fn:string-length(data($getClientInfoRes1/ns3:ListOfSoAccountInterfaceTopElmt/ns5:ListOfSoAccountInterface/ns5:Account/ns5:AccountId) )  = 0 ) then 
                                                    (		
                                                    
                                                    	for $SO_Ofertasporemail in $RelatedContact/ns0:SO_Ofertasporemail
                                                    	where $RelatedContact/ns0:SO_Ofertasporemail = 'Y'
                                                    	return
	                                                       <ns1:SO_Ofertasporemail>{ data($SO_Ofertasporemail) }</ns1:SO_Ofertasporemail> 
                    	            				)else(

	                                                    for $SO_Ofertasporemail in $RelatedContact/ns0:SO_Ofertasporemail
	                                                    return
	                                                        <ns1:SO_Ofertasporemail>{ data($SO_Ofertasporemail) }</ns1:SO_Ofertasporemail>                    	            				
                    	            					
                    	            				)                                          
                                                

                                                }                                                
                                                {
                                                 	for  $SO_EmailATG in $RelatedContact/ns0:SO_EmailATG
                                                    return
                                               			 <ns1:SO_EmailATG>{ data($SO_EmailATG) }</ns1:SO_EmailATG>
                                                }                                                                                          
                                                {
                                                    for $HomePhone in $RelatedContact/ns0:HomePhone
                                                    return
                                                        <ns1:HomePhone>{ data($HomePhone) }</ns1:HomePhone>
                                                }                                                      
                                                {
                                                    for $ContactIntegrationId in $RelatedContact/ns0:ContactIntegrationId
                                                    return
                                                        <ns1:ContactIntegrationId>{ data($ContactIntegrationId) }</ns1:ContactIntegrationId>
                                                }
                                                {
                                                    for $JobTitle in $RelatedContact/ns0:JobTitle
                                                    return
                                                        <ns1:JobTitle>{ data($JobTitle) }</ns1:JobTitle>
                                                }
                                                {
                                                if ( fn:string-length(for $RelatedContact in  $getClientInfoRes1/ns3:ListOfSoAccountInterfaceTopElmt/ns5:ListOfSoAccountInterface/ns5:Account/ns5:ListOfContact/ns5:RelatedContact                                      
                                            		where $RelatedContact/ns5:PersonUId=$getClientInfoRes1/ns3:ListOfSoAccountInterfaceTopElmt/ns5:ListOfSoAccountInterface/ns5:Account/ns5:Location
                                                	return 'aaaaaa')  > 0 ) then 
                                                	()
                                                	else 
                                                	<ns1:LastName>{ data($RelatedContact/ns0:LastName) }</ns1:LastName>
                                                	
                                                }
                                                {
                                                    for $MF in $RelatedContact/ns0:MF
                                                    return
                                                        <ns1:MF>{ data($MF) }</ns1:MF>
                                                }
                                                {
                                                    for $MiddleName in $RelatedContact/ns0:MiddleName
                                                    return
                                                        <ns1:MiddleName>{ data($MiddleName) }</ns1:MiddleName>
                                                }
                                                <ns1:PersonUId>{ data($RelatedContact/ns0:PersonUId) }</ns1:PersonUId>

                                                <ns1:PrimaryOrganization>Sodimac Chile</ns1:PrimaryOrganization>

                                                <ns1:SOTipoIdentificacion>{ data($RelatedContact/ns0:SOTipoIdentificacion) }</ns1:SOTipoIdentificacion>
                                                                                              
                                                <ns1:Status>{ data($RelatedContact/ns0:Status) }</ns1:Status>
                                                {
                                                    for $WorkPhone in $RelatedContact/ns0:WorkPhone
                                                    return
                                                        <ns1:WorkPhone>{ data($WorkPhone) }</ns1:WorkPhone>
                                                }
                                                {
                                                    for $WorkPhoneExtension in $RelatedContact/ns0:WorkPhoneExtension
                                                    return
                                                        <ns1:WorkPhoneExtension>{ data($WorkPhoneExtension) }</ns1:WorkPhoneExtension>
                                                }     
                                    
                                                {
                                                    for $CellularPhone in $RelatedContact/ns0:CellularPhone
                                                    return
                                                        <ns1:SOFechModCelularContacto>{ fn:substring(data($cli_get_info_res1/ns2:response/ns2:update_date),1,10) }</ns1:SOFechModCelularContacto>                                                                                                    
                                                }
                                                {
                                                    for $EmailAddress in $RelatedContact/ns0:EmailAddress
                                                    return
                                                        <ns1:SOFechModEmailATG>{fn:substring(data($cli_get_info_res1/ns2:response/ns2:update_date),1,10)  }</ns1:SOFechModEmailATG>                                                                                                    
                                                }                                           
                                                (:{
                                                    for $EmailAddress in $RelatedContact/ns0:EmailAddress
                                                    return
                                                        <ns1:SOFechModEmailContacto>{ fn:substring(data($cli_get_info_res1/ns2:response/ns2:update_date),1,10)  }</ns1:SOFechModEmailContacto>
                                                }:)
                                                {
                                                    if ( fn:string-length(data($getClientInfoRes1/ns3:ListOfSoAccountInterfaceTopElmt/ns5:ListOfSoAccountInterface/ns5:Account/ns5:AccountId) )  = 0 ) then 
                                                    (		for $SO_Ofertasporemail in $RelatedContact/ns0:SO_Ofertasporemail
                                                    		where $RelatedContact/ns0:SO_Ofertasporemail = 'Y'
                                                    		return
	                                                        	<ns1:SOFechModRecibeOfertas>{ fn:substring(data($cli_get_info_res1/ns2:response/ns2:update_date),1,10) }</ns1:SOFechModRecibeOfertas>                                                                                                    
                    	            					  
                    	            				)
                                					else (:Actualizacion:)
                                                    (		for $SO_Ofertasporemail in $RelatedContact/ns0:SO_Ofertasporemail
                                                    		return
    	                                                    	<ns1:SOFechModRecibeOfertas>{ fn:substring(data($cli_get_info_res1/ns2:response/ns2:update_date),1,10) }</ns1:SOFechModRecibeOfertas>                                                                                                    
                                                     ) 	
                                                }
                                                {
                                                    for $SOTelefonoContacto in $RelatedContact/ns0:HomePhone
                                                    return
                                                        <ns1:SOFechModTelefonoContacto>{ fn:substring(data($cli_get_info_res1/ns2:response/ns2:update_date),1,10)  }</ns1:SOFechModTelefonoContacto>
                                                }
                                               
                                               {
                                                    for $CellularPhone in $RelatedContact/ns0:CellularPhone
                                                    return
                                                        <ns1:SOSistemModCelularContacto>ATG</ns1:SOSistemModCelularContacto>                                                                                                    
                                                }
                                                {
                                                    for $EmailAddress in $RelatedContact/ns0:EmailAddress
                                                    return
                                                        <ns1:SOSistemModEmailATG>ATG</ns1:SOSistemModEmailATG>                                                                                                    
                                                }                                           
                                                (:{
                                                    for $EmailAddress in $RelatedContact/ns0:EmailAddress
                                                    return
                                                        <ns1:SOSistemModEmailContacto>ATG</ns1:SOSistemModEmailContacto>
                                                }:)
                                                {
                                                    if ( fn:string-length(data($getClientInfoRes1/ns3:ListOfSoAccountInterfaceTopElmt/ns5:ListOfSoAccountInterface/ns5:Account/ns5:AccountId) )  = 0 ) then 
                                                    (		for $SO_Ofertasporemail in $RelatedContact/ns0:SO_Ofertasporemail
                                                    		where $RelatedContact/ns0:SO_Ofertasporemail = 'Y'
                                                    		return
	                                                        	<ns1:SOSistemModRecibeOfertas>ATG</ns1:SOSistemModRecibeOfertas>
                    	            					  
                    	            				)
                                					else (:Actualizacion:)
                                                    (		for $SO_Ofertasporemail in $RelatedContact/ns0:SO_Ofertasporemail
                                                    		return
    	                                                    	<ns1:SOSistemModRecibeOfertas>ATG</ns1:SOSistemModRecibeOfertas>
                                                     )                                                                                                                                                             
                                                }
                                                {
                                                    for $SOTelefonoContacto in $RelatedContact/ns0:HomePhone
                                                    return
                                                        <ns1:SOSistemModTelefonoContacto>ATG</ns1:SOSistemModTelefonoContacto>
                                                }                                                 
                                            </ns1:RelatedContact>
                                            } 
                                </ns1:ListOfContact>
                        }
                        {
                            for $ListOfAccount_CreditProfile in $account/ns0:ListOfAccount_CreditProfile
                            return
                                <ns1:ListOfAccount_CreditProfile>
                                    {
                                        for $CreditProfile in $ListOfAccount_CreditProfile/ns0:CreditProfile
                                        return
                                            <ns1:CreditProfile>
                                                {
                                                    for $SOBlockCreditFlag in $CreditProfile/ns0:SOBlockCreditFlag
                                                    return
                                                        <ns1:SOBlockCreditFlag>{ data($SOBlockCreditFlag) }</ns1:SOBlockCreditFlag>
                                                }
                                                {
                                                    for $CreditAvailableAmount in $CreditProfile/ns0:CreditAvailableAmount
                                                    return
                                                        <ns1:CreditAvailableAmount>{ data($CreditAvailableAmount) }</ns1:CreditAvailableAmount>
                                                }
                                                <ns1:CreditArea>{ data($CreditProfile/ns0:CreditArea) }</ns1:CreditArea>
                                                {
                                                    for $CreditLimit in $CreditProfile/ns0:CreditLimit
                                                    return
                                                        <ns1:CreditLimit>{ data($CreditLimit) }</ns1:CreditLimit>
                                                }
                                                {
                                                    for $CreditProfileId in $CreditProfile/ns0:CreditProfileId
                                                    return
                                                        <ns1:CreditProfileId>{ data($CreditProfileId) }</ns1:CreditProfileId>
                                                }
                                                {
                                                    for $CreditProfileIntegrationId in $CreditProfile/ns0:CreditProfileIntegrationId
                                                    return
                                                        <ns1:CreditProfileIntegrationId>{ data($CreditProfileIntegrationId) }</ns1:CreditProfileIntegrationId>
                                                }
                                                {
                                                    for $CreditStatusCode in $CreditProfile/ns0:CreditStatusCode
                                                    return
                                                        <ns1:CreditStatusCode>{ data($CreditStatusCode) }</ns1:CreditStatusCode>
                                                }
                                                {
                                                    for $CreditStatusMessage in $CreditProfile/ns0:CreditStatusMessage
                                                    return
                                                        <ns1:CreditStatusMessage>{ data($CreditStatusMessage) }</ns1:CreditStatusMessage>
                                                }
                                                {
                                                    for $SOCreditUsed in $CreditProfile/ns0:SOCreditUsed
                                                    return
                                                        <ns1:SOCreditUsed>{ data($SOCreditUsed) }</ns1:SOCreditUsed>
                                                }
                                                {
                                                    for $RiskCategoryCode in $CreditProfile/ns0:RiskCategoryCode
                                                    return
                                                        <ns1:RiskCategoryCode>{ data($RiskCategoryCode) }</ns1:RiskCategoryCode>
                                                }
                                                {
                                                    for $SOAnalistaCredito in $CreditProfile/ns0:SOAnalistaCredito
                                                    return
                                                        <ns1:SOAnalistaCredito>{ data($SOAnalistaCredito) }</ns1:SOAnalistaCredito>
                                                }
                                                {
                                                    for $SOAutorizacionProxCompra in $CreditProfile/ns0:SOAutorizacionProxCompra
                                                    return
                                                        <ns1:SOAutorizacionProxCompra>{ data($SOAutorizacionProxCompra) }</ns1:SOAutorizacionProxCompra>
                                                }
                                                {
                                                    for $SOClasificacionExterna in $CreditProfile/ns0:SOClasificacionExterna
                                                    return
                                                        <ns1:SOClasificacionExterna>{ data($SOClasificacionExterna) }</ns1:SOClasificacionExterna>
                                                }
                                                {
                                                    for $SOClienteAfectoMora in $CreditProfile/ns0:SOClienteAfectoMora
                                                    return
                                                        <ns1:SOClienteAfectoMora>{ data($SOClienteAfectoMora) }</ns1:SOClienteAfectoMora>
                                                }
                                                {
                                                    for $SOFechaProximaCompra in $CreditProfile/ns0:SOFechaProximaCompra
                                                    return
                                                        <ns1:SOFechaProximaCompra>{ data($SOFechaProximaCompra) }</ns1:SOFechaProximaCompra>
                                                }
                                                {
                                                    for $SOFechaExpiracion in $CreditProfile/ns0:SOFechaExpiracion
                                                    return
                                                        <ns1:SOFechaExpiracion>{ data($SOFechaExpiracion) }</ns1:SOFechaExpiracion>
                                                }
                                                {
                                                    for $SOFormaPago in $CreditProfile/ns0:SOFormaPago
                                                    return
                                                        <ns1:SOFormaPago>{ data($SOFormaPago) }</ns1:SOFormaPago>
                                                }
                                                {
                                                    for $SOMontoProximaCompra in $CreditProfile/ns0:SOMontoProximaCompra
                                                    return
                                                        <ns1:SOMontoProximaCompra>{ data($SOMontoProximaCompra) }</ns1:SOMontoProximaCompra>
                                                }
                                                {
                                                    for $SOMotivoBloqueoCentral in $CreditProfile/ns0:SOMotivoBloqueoCentral
                                                    return
                                                        <ns1:SOMotivoBloqueoCentral>{ data($SOMotivoBloqueoCentral) }</ns1:SOMotivoBloqueoCentral>
                                                }
                                                {
                                                    for $SOCreditStatusDate in $CreditProfile/ns0:SOCreditStatusDate
                                                    return
                                                        <ns1:SOCreditStatusDate>{ data($SOCreditStatusDate) }</ns1:SOCreditStatusDate>
                                                }
                                                {
                                                    for $SOCreditThresholdLimit in $CreditProfile/ns0:SOCreditThresholdLimit
                                                    return
                                                        <ns1:SOCreditThresholdLimit>{ data($SOCreditThresholdLimit) }</ns1:SOCreditThresholdLimit>
                                                }
                                                {
                                                    for $SOSkipCreditCheck in $CreditProfile/ns0:SOSkipCreditCheck
                                                    return
                                                        <ns1:SOSkipCreditCheck>{ data($SOSkipCreditCheck) }</ns1:SOSkipCreditCheck>
                                                }
                                            </ns1:CreditProfile>
                                    }
                                </ns1:ListOfAccount_CreditProfile>
                        }
                        {
                            for $ListOfAccount_Industry in $account/ns0:ListOfAccount_Industry
                            return
                                <ns1:ListOfAccount_Industry>
                                    {
                                        for $RelatedIndustry in $ListOfAccount_Industry/ns0:RelatedIndustry
                                        return
                                            <ns1:RelatedIndustry>
						                        {
						                            if ( fn:string-length($getClientInfoRes1/ns3:ListOfSoAccountInterfaceTopElmt/ns5:ListOfSoAccountInterface/ns5:Account[1]/ns5:AccountId )  <= 0 ) then 
						                            	  <ns1:IsPrimaryMVG>Y</ns1:IsPrimaryMVG>  
						                            else 
						                            	()
						                        }                                            	
                                                <ns1:SICCode>{ data($RelatedIndustry/ns0:SICCode) }</ns1:SICCode>
                                            </ns1:RelatedIndustry>
                                    }
                                </ns1:ListOfAccount_Industry>
                        }
                        {
                            for $ListOfAccount_Organization in $account/ns0:ListOfAccount_Organization
                            return
                                <ns1:ListOfAccount_Organization>
                                    {
                                        for $RelatedOrganization in $ListOfAccount_Organization/ns0:RelatedOrganization
                                        return
                                            <ns1:RelatedOrganization>
                                                <ns1:Organization>{ data($RelatedOrganization/ns0:Organization) }</ns1:Organization>
                                                <ns1:OrganizationId>{ data($RelatedOrganization/ns0:OrganizationId) }</ns1:OrganizationId>
                                            </ns1:RelatedOrganization>
                                    }
                                </ns1:ListOfAccount_Organization>
                        }
                    </ns1:Account>
            }
        </ns1:ListOfSoAccountInterface>
};

declare variable $cli_get_info_res1 as element(ns2:cli_get_info_res) external;
declare variable $getClientInfoRes1 as element(ns3:getClientInfoRes) external;
declare variable $regiones as element(CrossRefecrence) external;

xf:Atg2Siebel(
	$cli_get_info_res1,
    $getClientInfoRes1,
    $regiones
    )